﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for dataAccess
/// </summary>
public class dataAccess
{

    SqlConnection con = null;
    SqlDataAdapter da;
    SqlCommand cmd;
    DataSet ds;

    String sqlCon = "server=.;database=TronThucAn;uid=sa;pwd=301411552";

	public dataAccess()
	{
		
	}

    public void getConnection()
    {
        if (con == null)
        {
            con = new SqlConnection(sqlCon);
        }if (con != null && con.State == ConnectionState.Closed)
        {
            con.Open();
        }
    }

    public void disConnection()
    {
        if (con != null && con.State == ConnectionState.Open)
        {
            con.Close();
        }
    }

    public void executeQuery(String sql)
    {
        getConnection();
        cmd = new SqlCommand(sql, con);
        cmd.ExecuteNonQuery();
        disConnection();
    }

    public DataSet getData(String sql)
    {
        getConnection();
        da = new SqlDataAdapter(sql, con);
        ds = new DataSet();
        da.Fill(ds);
        disConnection();
        return ds;
    }
}